//
//  SecondViewController.m
//  Poem
//
//  Created by xuPeng on 2017/12/26.
//  Copyright © 2017年 xuPeng. All rights reserved.
//

#import "SecondViewController.h"
#import "UILabel+TextFiled.h"
#define kTipAlert(s, ...) {UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""                                                      message:[NSString stringWithFormat:(s), ##__VA_ARGS__]                                                       preferredStyle:UIAlertControllerStyleAlert];UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault                                                     handler:^(UIAlertAction * action) {}];[alert addAction:defaultAction];[self presentViewController:alert animated:YES completion:nil];}
@interface SecondViewController ()
@property (nonatomic, strong)UILabel *labelTime;
@end

@implementation SecondViewController
{
    
    NSTimer *timeNow;
}



- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor orangeColor];
    kTipAlert(@"%@",@"我的家在东北");
    
    
    self.labelTime = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 50)];
    self.labelTime.text = @"我的家在东北";
    
    self.labelTime.backgroundColor = [UIColor redColor];
    self.labelTime.isTop = YES;
    
    
    
    [self.view addSubview:self.labelTime];
    
    timeNow = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
    
    
    
    //获取系统时间
    
    NSDate * senddate=[NSDate date];
    
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"HH:mm"];
    
    NSString * locationString=[dateformatter stringFromDate:senddate];
    
    NSLog(@"-------%@",locationString);
    
    //获取系统时间
    
    NSCalendar * cal=[NSCalendar currentCalendar];
    
    NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
    
    NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate];
    
    NSInteger year=[conponent year];
    
    NSInteger month=[conponent month];
    
    NSInteger day=[conponent day];
    
    NSString * nsDateString= [NSString stringWithFormat:@"%4d年%2d月%2d日",year,month,day];
    
    NSLog(@"+++++++++++++%@",nsDateString);
    
}

- (void)timerFunc
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM/dd/YY HH:mm:ss"];
    NSString *timestamp = [formatter stringFromDate:[NSDate date]];
    
//    [self.labelTime setText:timestamp];//时间在变化的语句

    NSLog(@"%@",timestamp);
    
}

@end
